package croppingplanap;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class LegendEntry extends JPanel implements MouseListener{

	private CroppingPlanAp app;
	private Crop activeCrop;
	private Crop myCrop;
	
	public LegendEntry(Crop myCrop, Crop activeCrop, CroppingPlanAp app){
		super(new FlowLayout(FlowLayout.RIGHT,4,0));
		this.app = app;
		this.myCrop = myCrop;
		this.activeCrop = activeCrop;
		
		
		this.add(new JLabel(myCrop.toString(), JLabel.RIGHT));
		JPanel colorLabel = new JPanel();
		Dimension d = new Dimension(20,20);
		colorLabel.setPreferredSize(d);
		colorLabel.setMinimumSize(d);
		colorLabel.setForeground(myCrop.getColor());
		colorLabel.setBackground(myCrop.getColor());
		colorLabel.setOpaque(true);
		this.add(colorLabel);
		if(myCrop == activeCrop){
			this.setBorder(BorderFactory.createLineBorder(Color.black));
		}else{
			this.setBorder(BorderFactory.createLineBorder(LegendPanel.BGCOLOR));
			this.addMouseListener(this);
		}
	}
	
	public void mouseClicked(MouseEvent arg0) {
		if(myCrop != activeCrop) app.setCropFromJava(myCrop);
	}

	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
